package
{
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import nl.stroep.db.Database;
	import nl.stroep.db.Entry;
	import nl.stroep.db.EntryTypes;
	import nl.stroep.db.Table;
	
	/**
	 * ...
	 * @author Mark Knol
	 */
	public class Main extends Sprite 
	{
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			
			
			// create instance of database
			var db:Database =  new Database("MyDatabase");

			// debug only: add console
			addChild(db.console);

			// create database
			db.createDatabase();

			var myTable:Table = new Table( "myTable", [
				new Entry("id", EntryTypes.INT, true),
				new Entry("name", EntryTypes.TEXT),
				new Entry("value", EntryTypes.TEXT),
			] );

			// create table inside database
			db.createTable( myTable );

			// add rows to table
			db.insertRow( myTable.name, ["name", "value"], ["Mark", "Hello-world"]);
			db.insertRow( myTable.name, ["name", "value"], ["John", "Hi-There"]);
			db.insertRow( myTable.name, ["name", "value"], ["Batman", "Test-entry"]);
			
		}
		
		
		
	}
	
}